<template>

  <el-select
    v-model="selectValue"
    filterable
    :clearable="false"
    @change="afterChange"
    :placeholder="$tt('tip_please_select')"
    >
    <el-option v-for="item in statusMap[productType]" :key="item.value" :label="item.label" :value="item.value">
    </el-option>
  </el-select>

</template>


<script>

import Vue from 'vue'

import { mapState } from "vuex";

export default {
  name: 'warehouse_select',
  data() {
    return {

      hasLoad: false,
      selectValue: '',
      statusMap: {
        "FIRST_TRANSPORT": [],
        "LAST_TRANSPORT": [],
        "EXPRESS": [],
      }

    }
  },

  watch: {
    // 'productType'(val, old) {
    // },
    value: function (val, old) {

      if (val) {
        this.selectValue = val
      } else {
        this.selectValue = ''
      }
    }
  },

  props:{

    value: null,

    'productType':{
      type: String,
      default: 'FIRST_TRANSPORT'
    }

  },

  created() {

    let _this = this

    if (this.value) {
      this.selectValue = this.value
    }

    if(Vue.prototype.$pmsPricePointHasLoad){
      let tmpMap = Vue.prototype.$pmsPricePointOptionCache
      for(let kk in tmpMap){
        _this.statusMap[kk] = tmpMap[kk]
      }
      return
    }

    _this.$ajax({
      url: '/oms-api/order/OrderStatusRpc/pointStatus.json',
      success: function (res) {
        Vue.prototype.$pmsPricePointOptionCache = res.data

        let tmpMap = Vue.prototype.$pmsPricePointOptionCache
        console.log(tmpMap)
        for(let kk in tmpMap){
          // 国际化处理
          tmpMap[kk].forEach(r=>{
            r.label = _this.$tt( r.typeEnum +  '__' + r.value)
          })

          _this.statusMap[kk] = tmpMap[kk]
        }
        Vue.prototype.$pmsPricePointHasLoad = true

      }
    })


  },

  methods: {

    afterChange(val) {
      this.$emit('input', val)
    }

  }
}
</script>
